package thread;

class SingletonLazy {
    private static volatile SingletonLazy instance = null;
    static final Object locked = new Object();

    public static SingletonLazy getSingletonLazy() {
        if(instance==null){
            synchronized (locked) {
                if (instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }

    private SingletonLazy() {
    }
}

public class test17 {
    private static SingletonLazy s1;
    private static SingletonLazy s2;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            s1 = SingletonLazy.getSingletonLazy();
        });

        Thread t2 = new Thread(() -> {
            s2 = SingletonLazy.getSingletonLazy();
        });

        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(s1 == s2);
    }
}
